package com.example.hxds.bff.driver.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import com.example.hxds.common.api.DriverApi;
import com.example.hxds.common.dto.RegisterNewDriverDTO;
import com.example.hxds.common.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app/driver")
@Tag(name = "AppDriverController",description = "小程序司机模块接口")
public class AppDriverController {

    @Autowired
    private DriverApi driverApi;

    /*
    * 司机注册接口（小程序）
    * */
    @PostMapping("/registerNewDriver")
    @Operation(summary = "司机注册")
    public R registerNewDriver(@RequestBody RegisterNewDriverDTO registerNewDriverDTO){
        R r = driverApi.registerNewDriver(registerNewDriverDTO);
        if (ObjectUtil.isNotEmpty(r.get("userId"))){
            StpUtil.login(r.get("userId"));
            String token = StpUtil.getTokenInfo().getTokenValue();
            return R.ok().put("token",token);
        }else {
            return r;
        }
    }

}
